package com.Xingcang_Dianxue.WhutBank.Controllers.Client;

import com.Xingcang_Dianxue.WhutBank.Models.Model;
import com.Xingcang_Dianxue.WhutBank.Models.Transaction;
import com.Xingcang_Dianxue.WhutBank.Views.TransactionCellFactory;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ListView;

import java.net.URL;
import java.util.ResourceBundle;

public class TransactionsListController implements Initializable {
    @FXML
    private ListView<Transaction> transaction_list;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        initList();
        transaction_list.setItems(Model.getInstance().getAllTransactions());
        transaction_list.setCellFactory(e -> new TransactionCellFactory());
    }

    private void initList() {
        if (Model.getInstance().getAllTransactions().isEmpty()) {
            Model.getInstance().setAllTransactions();
        }
    }
}
